﻿using LitJson;
using System.Collections.Generic;

namespace TableCore.Plugin
{
    public class StringFormatter : IGenFormatter, IGenCmdInitializer
    {
        //StringBuilder buffer = new StringBuilder();
        readonly char space = ' ';

        public IExportData ExportData(GTFile.Content content, string data, string cellName, string comment)
        {
            return null;
        }

        public JsonData Format(GTFile.Content content, string data, string cellName, string comment)
        {
            if (!string.IsNullOrEmpty(data))
            {
                var buffer = StringUtil.GetBuilder();
                buffer.Append(data);
                for (int i = 0; i < buffer.Length; i++)
                {
                    var c = buffer[i];
                    if ((int)c == 160)
                    {
                        buffer[i] = space;
                    }
                }
                return StringUtil.ReturnRelease(buffer);// buffer.ToString();
            }
            else
            {
                return null;
            }
        }

        public void Init(GTType type, Dictionary<string, string> args, string content)
        {
        }

        public bool IsValid(string data)
        {
            return true;
        }

    }
}
